/** @format */
const path = require("path");

const { Daily } = require("../model/index");
/**
 * @format
 * @param {Request} req
 * @param {Response} res
 */

module.exports.getDailyById = async (req, res, next) => {
  const dbb = await Daily.findOne(req.query);
  const options = {
    root: path.join(path.dirname(__dirname, "../"), "public/daily"),
    dotfiles: "deny",
    headers: {
      "x-timestamp": Date.now(),
      "x-sent": true,
    },
  };

  const fileName = dbb.url;
  res.sendFile(fileName, options, function (err) {
    if (err) {
      next(err);
    } else {
      console.log("Sent:", fileName);
    }
  });
};

module.exports.getDaily = async (req, res, next) => {
  const dbb = await Daily.find(req.query);
  res.data = dbb;
  res.msg = "获取成功";
  res.status(200);
  next();
};
